<?php

class AdminHome extends Controller
{
    public function index()
    {
    	//print "<pre>" . print_r($_SESSION , true ) . "<pre>"; exit;
    	if(!isset($_SESSION['admin']) || empty($_SESSION['admin'])) {
        	require APP . 'views/adminHome/signin.php';
    	} else {
    		
    		$pendingProductCount = $this->model->getPendingProductsCount();
    		$pendingCommentsCount = $this->model->getPendingCommentsCount();
    		
    		// load views
	        require APP . 'views/admin_templates/header.php';
	        require APP . 'views/adminHome/index.php';
	        require APP . 'views/admin_templates/footer.php';
    	}
    }


    public function signin()
    {
        if (isset($_POST["submit_signin"])) {
            $adminInfo = $this->model->signin($_POST["username"],$_POST["password"]);
            
            if(!empty($adminInfo)) {
            	$_SESSION['admin'] = array();
            	$_SESSION['admin']['username'] = $adminInfo[0]->username;
            	$_SESSION['admin']['role'] = $adminInfo[0]->role;
            }
        }
        header('location: ' . URL . 'adminHome');
    }
    
	public function signout()
    {
        $_SESSION = array();
        header('location: ' . URL . 'adminHome');
    }
    
	public function signup($username,$password)
    {
        if (isset($_POST["submit_signup"])) {
            $this->model->signup($_POST["username"],$_POST["password"]);
             header('location: ' . URL . 'adminHome');
        }
		else {
		 header('location: ' . URL . 'adminHome');
       }
	}
}
